package com.yjzx.util.service.pay.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.yjzx.util.service.pay.config.properties.AlipayProperties;
import com.yjzx.util.service.pay.constants.BaseConstant;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yjzx
 * @Description
 * @create 2022-12-24 11:25
 */
@Configuration
public class AlipayConfig {

    @Bean(name = "alipayAppClient")
    AlipayClient alipayAppClient(AlipayProperties alipayProperties){
        AlipayProperties.AliApplication app = alipayProperties.getApp();
        return new DefaultAlipayClient(alipayProperties.getGatewayUrl(),
                app.getAppId(),
                app.getMerchantPrivateKey(),
                BaseConstant.JSON,
                alipayProperties.getCharset(),
                app.getAlipayPublicKey(),
                alipayProperties.getSignType());
    }
    @Bean("alipayMiniClient")
    AlipayClient alipayMiniClient(AlipayProperties alipayProperties){
        AlipayProperties.AliApplication app = alipayProperties.getMini();
        return new DefaultAlipayClient(alipayProperties.getGatewayUrl(),
                app.getAppId(),
                app.getMerchantPrivateKey(),
                BaseConstant.JSON,
                alipayProperties.getCharset(),
                app.getAlipayPublicKey(),
                alipayProperties.getSignType());
    }
    @Bean("alipayHtmlClient")
    AlipayClient alipayHtmlClient(AlipayProperties alipayProperties){
        AlipayProperties.AliApplication app = alipayProperties.getHtml();
        return new DefaultAlipayClient(alipayProperties.getGatewayUrl(),
                app.getAppId(),
                app.getMerchantPrivateKey(),
                BaseConstant.JSON,
                alipayProperties.getCharset(),
                app.getAlipayPublicKey(),
                alipayProperties.getSignType());
    }


}
